<template>
  <el-table :data="dataList" border fit highlight-current-row @selection-change="handleSelectionChange">
    <!-- <el-table-column type="selection" width="55">
    </el-table-column> -->
    <el-table-column v-for="(item) in engTh" :key="item" :label="formTh[`${item}`]">
      <template v-slot="scope">
        {{ scope.row[`${item}`] }}
      </template>
    </el-table-column>
    <el-table-column fixed="right" label="操作" width="150">
      <template v-slot="scope">
        <!-- <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)">修改</el-button> -->
        <el-button size="mini" type="text" icon="el-icon-delete"
          @click="handleDelete(scope.row.businessId)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>
  


<script lang="ts" setup>
import { exportExcel, filterExcelContentArr } from "@/utils/excel";
import { purTableHeader, purTableProps } from "./data";
import { onMounted } from "vue";
import { deleteMatCostType } from "@/requests/api/material";
import { Message, MessageBox } from "element-ui";


const props = defineProps({
  dataList: Array<any>,
  engTh: Array<String | null>
});
const formTh = Object.assign(purTableHeader)
const emit = defineEmits(['showJournalList', 'refreshTable'])
const handleDelete = async (v: string) => {
  MessageBox.confirm('是否确认删除业务ID为"' + v + '"的成本类型？').then(async () => {
    const res = await deleteMatCostType(v)
    if (res.data) {
    } else {
      Message.error('删除失败')
    }
  }).then(() => {
    emit('refreshTable');
    Message.success("删除成功");
  }).catch(() => { });

}
onMounted(() => {
  console.log('数据123', formTh, props.dataList)
})

let selectedArr: Array<any> = []
const handleSelectionChange = (val: Array<any>) => {
  console.log('选择的值', val);
  selectedArr = val;
}
const exportItems = () => {
  const sheetArr = filterExcelContentArr(selectedArr, purTableProps, purTableHeader)
  console.log('过滤的值', sheetArr)
  exportExcel("事务处理明细.xlsx", sheetArr)

}
// 暴露出去被引用
defineExpose({
  exportItems
})
// const handleItem = (key: any, value: any) => {
//   return value
// }
</script>
